﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Web.Old_App_Code;


public partial class backstage_order_report_forms : System.Web.UI.Page
{
    // Fields

    protected OrderGoodsEntitysManager ogem = new OrderGoodsEntitysManager();
    protected OrderManager om = new OrderManager();
    protected string webSiteXmlPaht = "/cn/xml/website_set.xml";

    // Methods
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "location.href=\"login.html\";", true);
        }
        else
        {
            ReportDocument document = new ReportDocument();
            if ((base.Request.QueryString["id"] != null) && (base.Request.QueryString["orderNo"] != null))
            {
                DataTable orderById = this.om.GetOrderById(Convert.ToInt32(base.Request.QueryString["id"]));
                DataTable orderGoodsEntitysByOrderNo = this.ogem.GetOrderGoodsEntitysByOrderNo(base.Request.QueryString["orderNo"]);
                document.Load(base.Server.MapPath("/report/OrderCrystalReport.rpt"));
                document.SetDataSource(orderGoodsEntitysByOrderNo);
                this.crvOrder.ReportSource = document;
                document.SetParameterValue("title", "订单");
                XmlDocument document2 = new XmlDocument();
                document2.Load(base.Server.MapPath(this.webSiteXmlPaht));
                XmlElement element = document2.SelectSingleNode("set/cn_enterprise_name") as XmlElement;
                document.SetParameterValue("companyName", element.GetAttribute("value"));
                if (orderById.Rows.Count > 0)
                {
                    DataRow row = orderById.Rows[0];
                    document.SetParameterValue("orderNo", row["orderNo"].ToString());
                    document.SetParameterValue("createTime", Convert.ToDateTime(row["createTime"]).ToString("yyyy年MM月dd日HH时mm分ss秒"));
                    document.SetParameterValue("consignee", row["consignee"].ToString());
                    document.SetParameterValue("region", row["region"].ToString());
                    document.SetParameterValue("address", row["address"].ToString());
                    document.SetParameterValue("zipCode", row["zipCode"].ToString());
                    document.SetParameterValue("telephone", row["telephone"].ToString());
                    document.SetParameterValue("mobile", row["mobile"].ToString());
                    document.SetParameterValue("deliveryWay", row["deliveryWay"].ToString());
                    document.SetParameterValue("payment", row["payment"].ToString());
                    document.SetParameterValue("operator", (this.Session["admin_user"] as Admin).Name);
                    document.SetParameterValue("goodsTotal", string.Format("{0:C}", row["goodsTotal"].ToString()));
                    document.SetParameterValue("orderTotal", string.Format("{0:C}", row["orderTotal"].ToString()));
                    document.SetParameterValue("deliveryMoney", string.Format("{0:C}", row["deliveryMoney"].ToString()));
                    document.SetParameterValue("postscript", row["postscript"].ToString());
                    document.SetParameterValue("orderRemark", row["orderRemark"].ToString().Replace("<br />", " ").Replace("&nbsp;", ""));
                }
            }
        }
    }

}